home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / bsrc_p1.arc / BT.C < prev    next >
Text File  |  1988-11-29  |  15KB  |  536 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software <no-Inc>                   */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          No-Cost<no-tm> Software.                       */
  7. /*        \ 1011 /                                                          */
  8. /*         ------            KopyRong (K) 1987.  ALL RIGHTS REVERSED.       */
  9. /*                                                                          */
  10. /*                                                                          */
  11. /*         This module was originally written by Wynn Wagner III            */
  12. /*     with significant changes made by Vince Perriello and Bob Hartman     */
  13. /*                                                                          */
  14. /*                                                                          */
  15. /*           BinkleyTerm "Main" Module: Terminal Emulation and              */
  16. /*                       File Transfer dispatching                          */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*   This  software  package is being distributed WITH FULL SOURCE CODE     */
  20. /*   with the  following  conditions:    1)  If  anything awful happens     */
  21. /*   because  you  use    it   (or  don't  use  it),  you  accept  full     */
  22. /*   responsibility;  2) you  don't start making tons of voice calls to     */
  23. /*   the authors to complain or  make  suggestions  about enhancements,     */
  24. /*   useful or otherwise;  3) you  do not reuse this code in commercial     */
  25. /*   products without specific permission to do so  from  the  authors;     */
  26. /*   4) If you find any problems you send  fixes  to  the  authors  for     */
  27. /*   inclusion  in  updates;    5) You find some way  to  express  your     */
  28. /*   appreciation  for  this  method of distribution, either by writing     */
  29. /*   code or  application  notes,  or  just sending along a "Thank You"     */
  30. /*   message.                                                               */
  31. /*                                                                          */
  32. /*   There is  copyrighted  code  in  this product.  We either wrote it     */
  33. /*   ourselves or got  permission  to use it.  Please don't force us to     */
  34. /*   pay a lawyer --  have some respect for our motives and don't abuse     */
  35. /*   this "license".                                                        */
  36. /*                                                                          */
  37. /*                                                                          */
  38. /*--------------------------------------------------------------------------*/
  39.  
  40.  
  41. #include <stdio.h>
  42. #include <signal.h>
  43. #include <ctype.h>
  44. #include <conio.h>
  45. #include "com.h"
  46. #include "xfer.h"
  47. #include "keybd.h"
  48.  
  49. struct pointers ctl;
  50.  
  51. struct baud_str btypes[] = {
  52.     {     "300",  BAUD_300   },
  53.     {    "1200",  BAUD_1200  },
  54.     {    "2400",  BAUD_2400  },
  55.     {    "4800",  BAUD_4800  },
  56.     {    "9600",  BAUD_9600  },
  57.     {    "19200", BAUD_19200 },
  58.     {      NULL,  0 }
  59. };
  60.  
  61. int baud,cur_baud,locate_x,locate_y,port_ptr;
  62.  
  63. int share = 0;                /* if 1, don't uninit FOSSIL  */
  64. int boss_net = 0;
  65. int boss_node = 0;
  66. int un_attended = 0;
  67. int command_line_un;
  68. int overwrite = 0;
  69. int redo_dynam = 0;
  70. int fullscreen = 1;
  71. int BBStimeout = 2000;
  72. int loglevel = 10;
  73. extern int remote_net, remote_node;
  74. extern struct _node nodedes;        /* desc. of node             */
  75. extern int caller;
  76. extern int noforce;
  77.  
  78. char *BBSopt = NULL;            /* BBS command options       */
  79. char *BBSbanner = NULL;            /* BBS banner                */
  80. char *BBSreader = NULL;    /* Message reader */
  81. char *BOSSphone = NULL;    /* Phone number for boss */
  82.  
  83. char *BINKpath = "";
  84.  
  85. char junk[100];
  86.  
  87. main (argc, argv)
  88. int argc;
  89. char *argv[];
  90. {
  91. int k;
  92. int c;
  93. int done;
  94. long t1;
  95. char *envptr,*getenv(),*malloc();
  96. FILE *logfile = NULL;            /* log file stream descriptor */
  97. char prot;
  98. int err;
  99. int mail_only = 0;            /* if 1, do mail and exit     */
  100. int bnet, bnode;
  101. extern long timerset();
  102. extern char *receive_file();
  103.  
  104. envptr = getenv("BINKLEY");        /* get path from environment */
  105. if ((envptr != NULL)            /* If there was one, and     */
  106. && (!dexists("Binkley.Cfg")))        /* No BINKLEY.CFG locally,   */
  107.     {
  108.     BINKpath = malloc(strlen(envptr) + 1);    /* make room for new */
  109.     strcpy(BINKpath,envptr);    /* use BINKLEY as our path   */
  110.     }
  111.  
  112. signal (SIGINT, SIG_IGN);
  113. tzset();
  114.  
  115. ctl.handshake_mask = USE_XON|USE_CTS;
  116. ctl.carrier_mask = 0x80;
  117. ctl.hold_area = ctl.filepath = ctl.net_info = NULL;
  118. ctl.avail_list = ctl.request_list = ctl.freq_about = NULL;
  119. ctl.predial = ctl.postdial = ctl.m_init = NULL;
  120. ctl.matrix_mask = TAKE_REQ;
  121. ctl.system_name = ctl.sysop = NULL;
  122. ctl.our_zone = 1;
  123. ctl.max_baud = 0;
  124.  
  125. b_init();
  126.  
  127. baud = 2;
  128. cur_baud = atoi(btypes[baud].str);
  129. command_line_un = 0;
  130.  
  131. while (--argc)
  132.     {
  133.     ++argv;
  134.    if (strnicmp (argv[0], "noforce", 7) == 0)
  135.       {
  136.       noforce = 1;
  137.       continue;
  138.       }
  139.     else if (strnicmp(argv[0],"mail",4) == 0)
  140.         {
  141.         ++mail_only;
  142.         continue;
  143.         }
  144.     else if (strnicmp(argv[0],"share",5) == 0)
  145.         {
  146.         ++share;
  147.         continue;
  148.         }
  149.     else if (strnicmp(argv[0],"dynam",5) == 0)
  150.         {
  151.         ++redo_dynam;
  152.         continue;
  153.         }
  154.    else if (strnicmp(argv[0],"unattended",10) == 0)
  155.       {
  156.       un_attended = 1;
  157.       command_line_un = 1;
  158.       continue;
  159.       }
  160.     else
  161.         {
  162.         printf("\r\nUnrecognized option: %s\r\n",argv[0]);
  163.         exit(1);
  164.         }
  165.     }
  166.  
  167. read_sched();
  168. parse_config();
  169.  
  170. if (Cominit(port_ptr) != 0x1954)
  171.     {
  172.     cprintf ("I'm sorry, there doesn't appear to be a FOSSIL driver loaded.\r\n");
  173.     cprintf ("BinkleyTerm requires a FOSSIL driver. Please take care of this before\r\n");
  174.     cprintf ("attempting to run BinkleyTerm again.\r\n");
  175.     exit (1);
  176.     }
  177.  
  178. k = un_attended;
  179. un_attended = 0;
  180. set_baud (ctl.max_baud, 0);
  181. un_attended = k;
  182. MDM_ENABLE(btypes[baud].rate);
  183. DTR_ON();
  184. XON_ENABLE();
  185. done = 0;
  186.  
  187. if (mail_only)
  188.     {
  189.    if (fullscreen)
  190.       {
  191.       opening_banner ();
  192.       mailer_banner ();
  193.       }
  194.    un_attended = 1;
  195.     boss_mail(0);
  196.    un_attended = 0;
  197.     done = 1;
  198.     }
  199. else if (un_attended)
  200.    {
  201.    done = unattended();
  202.    }
  203. else
  204.    {
  205.    opening_banner ();
  206.    }   
  207.  
  208. while (!done)
  209.     {
  210.    c = -1;
  211.     if (CHAR_AVAIL())
  212.         {
  213.         c = MODEM_IN();
  214.         WRITE_ANSI(c);
  215.         if (logfile != NULL)
  216.             {
  217.             fwrite(&c,1,1,logfile);
  218.             }
  219.         }
  220.     if (KEYPRESS())
  221.         {
  222.       c = 0;
  223.         k = FOSSIL_CHAR();
  224.         switch (k)
  225.             {
  226.             case ALTX:
  227.             if (logfile != NULL)
  228.                 fclose(logfile);
  229.             done = 1;
  230.             break;
  231.  
  232.             case ALTH:
  233.             t1 = timerset (300);
  234.             while (CARRIER)
  235.                 if (timeup(t1))
  236.                     {
  237.                     scr_printf ("\r\nUnable to force carrier drop by dropping DTR!\r\n");
  238.                     break;
  239.                     }
  240.                 else
  241.                     {
  242.                     DTR_OFF();
  243.                     }
  244.             DTR_ON();
  245.             break;
  246.  
  247.             case ALTY:
  248.             scr_printf("\r\nBinkleyTerm now in MAILER mode\r\n");
  249.             boss_mail(1);
  250.             scr_printf("\r\nBinkleyTerm now in MANUAL mode\r\n");
  251.             break;
  252.  
  253.             case ALTL:
  254.             if (logfile != NULL)
  255.                 {
  256.                 fclose(logfile);
  257.                 logfile = NULL;
  258.                 scr_printf("\r\nLog file closed.\r\n");
  259.                 break;
  260.                 }
  261.             /* else */
  262.             scr_printf ("\r\nLog file name: ");
  263.             fgets (junk, 100, stdin);
  264.             if ((k = strlen(junk)) > 2)
  265.                 {
  266.                 junk[--k] = '\0'; /* no '\n' */
  267.                 logfile = fopen(junk,"ab");
  268.                 if (logfile == NULL)
  269.                     scr_printf("\r\nCould not open specified logfile.\r\n");
  270.                 }
  271.             break;
  272.  
  273.             case ALTD:
  274.             scr_printf ("\r\nPlease enter a phone (or net/node) number: ");
  275.             fgets (junk, 100, stdin);
  276.             if ((k = strlen(junk)) < 3)
  277.                 break;
  278.             junk[--k] = '\0';     /* no '\n' */
  279.             if (strchr(junk,'/') != NULL)
  280.                 {
  281.                 if (!nodeproc(junk))
  282.                     break;
  283.                 }
  284.             else
  285.                 {
  286.                 strcpy (nodedes.phone, junk);
  287.                 }
  288.             caller = 0;
  289.             try_2_connect(nodedes.phone);    /* try to connect         */
  290.             break;
  291.  
  292.             case ALTM:
  293.             scr_printf ("\r\nPlease enter a net/node number: ");
  294.             fgets (junk, 100, stdin);
  295.             if ((k = strlen(junk)) < 3)
  296.                 break;
  297.             junk[--k] = '\0';     /* no '\n' */
  298.             if (sscanf (junk, "%d/%d", &bnet, &bnode) == 2)
  299.                 {
  300.                 if (bnet >=0 && bnode >= 0)
  301.                     {
  302.                     scr_printf("\r\nBinkleyTerm now in MAILER mode\r\n");
  303.                     do_mail (bnet, bnode);
  304.                     scr_printf("\r\nBinkleyTerm now in MANUAL mode\r\n");
  305.                     break;
  306.                     }
  307.                 }
  308.             cprintf ("\r\nCannot get net/node from '%s'\r\n", junk);
  309.             break;
  310.  
  311.             case ALTB:
  312.             ++baud;
  313.             if (btypes[baud].str == NULL)
  314.                 baud = 0;
  315.             MDM_ENABLE(btypes[baud].rate);
  316.             cur_baud = atoi(btypes[baud].str);
  317.             scr_printf ("\r\nBinkleyTerm now communicating at ");
  318.             scr_printf (btypes[baud].str);
  319.             scr_printf (" baud.\r\n");
  320.             break;
  321.  
  322.             case ALTP:
  323.             port_ptr = !port_ptr;
  324.             MDM_DISABLE();
  325.             Cominit(port_ptr);
  326.             MDM_ENABLE(btypes[baud].rate);
  327.             DTR_ON();
  328.             scr_printf ("\r\nBinkleyTerm now using COM");
  329.             WRITE_ANSI (port_ptr + '1');
  330.             scr_printf (":\r\n");
  331.             XON_ENABLE();
  332.             break;
  333.  
  334.             case ALTU:
  335.             done = unattended();
  336.             break;
  337.  
  338.             case PGUP:
  339.             XON_DISABLE();
  340.             scr_printf("\r\nBinkleyTerm is ready to SEND a file...\r\n");
  341.             scr_printf("Which Protocol do you want BinkleyTerm to use?\r\n");
  342.             scr_printf("Z)modem     Y)modem     S)EAlink     T)elink     X)modem\r\n");
  343.             scr_printf("OK....Choose! ");
  344.             fgets (junk, 100, stdin);
  345.             prot = toupper (junk[0]);
  346.             if ((prot != 'X') && (prot != 'Y')
  347.             && (prot != 'S') &&  (prot != 'Z')
  348.             && (prot != 'T'))
  349.                 {
  350.                 scr_printf ("Sorry. I don't know that protocol, returning to terminal mode.\r\n");
  351.                 break;
  352.                 }
  353.             scr_printf ("File to be sent? ");
  354.             fgets (junk, 100, stdin);
  355.             junk[strlen(junk) - 1] = '\0';
  356.             err = 1;
  357.             if (prot == 'Z')
  358.                 {
  359.                 Send_Zmodem(junk,NULL,0,0,0);
  360.                 Send_Zmodem(NULL,NULL,0,END_BATCH,0);
  361.                 XON_ENABLE();
  362.                 break;
  363.                 }
  364.             if (prot == 'T')
  365.                 err = xfermdm7(junk);
  366.             if (err)    /* 'X','Y','Z' or good MDM7 filename */
  367.                 {
  368.                 send_file (junk,prot);
  369.                 send_file (NULL, prot);
  370.                 }                
  371.             XON_ENABLE();
  372.             break;
  373.  
  374.             case PGDN:
  375.             XON_DISABLE();
  376.             scr_printf("\r\nBinkleyTerm is ready to RECEIVE a file...\r\n");
  377.             scr_printf("Which Protocol do you want BinkleyTerm to use?\r\n");
  378.             scr_printf("Z)modem     Y)modem     S)EAlink     T)elink     X)modem\r\n");
  379.             scr_printf("OK....Choose! ");
  380.             fgets (junk, 100, stdin);
  381.             prot = toupper (junk[0]);
  382.             junk[0] = '\0';
  383.             if ((prot == 'X') || (prot == 'Y'))
  384.                 {
  385.                 scr_printf ("File to receive? ");
  386.                 fgets (junk, 100, stdin);
  387.                 junk[strlen(junk) - 1] = '\0';
  388.                 receive_file( "", junk, prot);
  389.                 XON_ENABLE();
  390.                 break;
  391.                 }
  392.             if (prot == 'Z')
  393.                 {
  394.                 get_Zmodem("",NULL);
  395.                 XON_ENABLE();
  396.                 break;
  397.                 }
  398.             if ((prot != 'T') && (prot != 'S'))
  399.                 {
  400.                 scr_printf ("Sorry. I don't know that protocol, returning to terminal mode.\r\n");
  401.                 break;
  402.                 }
  403.             else
  404.                 {
  405.                 err = 1;
  406.                 while (err)
  407.                     {
  408.                     if (prot == 'T')
  409.                         err = recvmdm7(junk);
  410.                     if (err)
  411.                         err = (receive_file( "", junk, prot) != NULL);
  412.                     }
  413.                 }
  414.             XON_ENABLE();
  415.             break;
  416.  
  417.             case ALTF10:
  418.             main_help();
  419.             break;
  420.  
  421.             default:
  422.             c = k & 0xff;
  423.             if (c != 0)
  424.                 while (Com_Tx_NW (c) == 0)
  425.                     ;
  426.             else
  427.                 ansi_map(k);
  428.             }
  429.         }
  430.    if (c == -1)
  431.       time_release();
  432.     }
  433. if (command_line_un)
  434.    {
  435.    mdm_init (ctl.m_busy);
  436.    DTR_OFF();
  437.    }
  438.  
  439. gotoxy (0, 22);
  440. while (KEYPRESS())
  441. {
  442.    FOSSIL_CHAR();
  443. }
  444. if (!share)
  445.     MDM_DISABLE();
  446. cprintf ("Thanks for using BinkleyTerm.\033[K\r\nHope to see you again real soon!\033[K\r\n");
  447. exit (1);
  448. }
  449.  
  450. /*--------------------------------------------------------------------------*/
  451. /*                                                                          */
  452. /* ansi_map() -- map function key into an ANSI escape sequence if we have   */
  453. /* one to correspond to the key. The "emulation" is VT100-type, we map the  */
  454. /* arrow keys to the ANSI escape sequences for up, down, right and left,    */
  455. /* and we map the function keys into the VT100 keypad, assuming application */
  456. /* mode, like Procomm. That is, we take the VT100 keypad, split it in two   */
  457. /* vertically, and use the F-keys to represent the left side, and the       */
  458. /* "shifted" F-keys to represent the right side.                            */
  459. /*                                                                          */
  460. /*              The result, if any, is transmitted to the host.             */
  461. /*                                                                          */
  462. /*--------------------------------------------------------------------------*/
  463.  
  464. char *ansi_seq[] = {    /* IBM key    Scan code    VT100 key    */
  465.     "\033OP",    /* F1        3b00        PF1        */
  466.     "\033OQ",    /* F2        3c00        PF2        */
  467.     "\033Ow",    /* F3        3d00        keypad '7'    */
  468.     "\033Ox",    /* F4        3e00        keypad '8'    */
  469.     "\033Ot",    /* F5        3f00        keypad '4'    */
  470.     "\033Ou",    /* F6        4000        keypad '5'    */
  471.     "\033Oq",    /* F7        4100        keypad '1'    */
  472.     "\033Or",    /* F8        4200        keypad '2'    */
  473.     "\033Op",    /* F9        4300        keypad '0'    */
  474.     "\033Op",    /* F10        4400        keypad '0'    */
  475.     "",        /*        4500                */
  476.     "",        /*        4600                */
  477.     "",        /*        4700                */
  478.     "\033[A",    /* Up Arrow    4800        Up Arrow    */
  479.     "",        /*        4900                */
  480.     "",        /*        4a00                */
  481.     "\033[D",    /* Left Arrow    4b00        Left Arrow    */
  482.     "",        /*        4c00                */
  483.     "\033[C",    /* Right Arrow    4d00        Right Arrow    */
  484.     "",        /*        4e00                */
  485.     "",        /*        4f00                */
  486.     "\033[B",    /* Down Arrow    5000        Down Arrow    */
  487.     "",        /*        5100                */
  488.     "",        /*        5200                */
  489.     "",        /*        5300                */
  490.     "\033OR",    /* Shift-F1    5400        PF3        */
  491.     "\033OS",    /* Shift-F2    5500        PF4        */
  492.     "\033Oy",    /* Shift-F3    5600        keypad '9'    */
  493.     "\033Om",    /* Shift-F4    5700        keypad '-'    */
  494.     "\033Ov",    /* Shift-F5    5800        keypad '6'    */
  495.     "\033Ol",    /* Shift-F6    5900        keypad ','    */
  496.     "\033Os",    /* Shift-F7    5a00        keypad '3'    */
  497.     "\033OM",    /* Shift-F8    5b00        keypad 'Enter'    */
  498.     "\033On",    /* Shift-F9    5c00        keypad '.'    */
  499.     "\033OM",    /* Shift-F10    5d00        keypad 'Enter'    */
  500.     ""
  501.     };
  502.  
  503. ansi_map(ScanVal)
  504. unsigned ScanVal;
  505. {
  506. register KeyCode;
  507. register char *s,c;
  508. KeyCode = ScanVal >> 8;            /* Isolate to key scan code */
  509. if ((KeyCode < 0x3b) || (KeyCode > 0x5d))
  510.     return;                /* Not in range, give up    */
  511. s = ansi_seq[KeyCode - 0x3b];        /* Index to our sequence    */
  512. while (c = *s++)            /* Until the end of string, */
  513.     {
  514.     while (Com_Tx_NW (c) == 0)    /* Keep sending those chars */
  515.         ;
  516.     }
  517. }
  518.  
  519. opening_banner ()
  520. {
  521. scr_printf ("\033[H\033[2J");
  522. scr_printf (ANNOUNCE);
  523. if (!un_attended)
  524.     scr_printf ("A Companion Package for communicating with the Opus CBCS\r\n");
  525. else
  526.     scr_printf ("A Public Domain FidoNet Compatible Mail Utility\r\n");
  527.  
  528. scr_printf ("Setting COM");
  529. WRITE_ANSI (port_ptr + '1');
  530. scr_printf (": to initial speed of ");
  531. scr_printf (btypes[baud].str);
  532. scr_printf (" baud. Press Alt-F10 for HELP.\r\n");
  533. fossil_ver();
  534. mtask_find();
  535. }
  536.